from pydantic_settings import BaseSettings
import os


class Settings(BaseSettings):
    SECRET_KEY: str = os.getenv("SECRET_KEY", "default-secret-key")
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 1440
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7
    DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite:///./old_app.db")
    REDIS_URL: str = "redis://localhost:6379/0"  # 添加这一行

    # Test：是否生成测试数据
    TEST_SQLITE_DATABASE: bool = False

    # 设备状态检查间隔（秒）
    DEVICE_STATUS_CHECK_INTERVAL: int = 240
    # 设备心跳超时时间（秒）
    DEVICE_HEARTBEAT_TIMEOUT: int = 60
    # 批量更新队列大小
    UPDATE_QUEUE_BATCH_SIZE: int = 50
    # 批量更新处理间隔（秒）
    UPDATE_QUEUE_BATCH_INTERVAL: float = 0.5
    # 缓存过期时间（秒）
    CACHE_EXPIRE_TIME: int = 3600
    # 缓存刷新间隔（秒）
    REFRESH_CACHE_PERIODICALLY_INTERVAL: int = 60

    # SQLITE数据库参数
    POOL_SIZE: int = 100    # 连接池大小
    MAX_OVERFLOW: int = 200 # 连接池溢出大小
    POOL_TIMEOUT: int = 30  # 连接池超时时间
    POOL_RECYCLE: int = 300 # 连接池回收时间

    DEFAULT_BATCH_NUMBER: str =  "temp"

    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"


settings = Settings()